﻿#region The MIT License (MIT)
// The MIT License (MIT)
// Copyright (c) 2010 - 2013 Sovacode LLC
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#endregion

/* Importing namespaces */
using Sovacode.RubiksCube.Common.ViewModel;

namespace Sovacode.DemoApp.ViewModel
{
    /// <summary>
    /// Setting Manager View Model, see how to implement work with local config file at <see cref="LocalSettings"/>
    /// </summary>
    public sealed class SettingsViewModel /*
                                           * Demonstration how to use Settings Manager.
                                           * 
                                           */
        : BasicViewModel.ChildsHolderViewModel
    {

        #region Private Fields

        private string _stringSetting = string.Empty;
        private int _intSetting;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="SettingsViewModel"/> class.
        /// </summary>
        public SettingsViewModel()
        {
            LoadSettings();
        }

        #endregion

        #region Override of Load/Save Settings

        /// <summary>
        /// Save settings
        /// </summary>
        protected override void SaveSettings()
        {
            /* Put string setting to local config file */
            SettingsManager.PutStringSetting(() => StringSetting, StringSetting);

            /* Put int setting to local config file */
            SettingsManager.PutInt32Setting(() => IntSetting, IntSetting);

            base.SaveSettings();
        }

        /// <summary>
        /// Load Settings
        /// </summary>
        public override void LoadSettings()
        {
            base.LoadSettings();

            /* Get string setting from local config file */
            StringSetting = SettingsManager.GetStringSetting(() => StringSetting);

            /* Get int setting from local config file */
            IntSetting = SettingsManager.GetInt32Setting(() => IntSetting);
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// String Setting
        /// </summary>
        public string StringSetting
        {
            /* Get string setting from local config file */
            get { return _stringSetting; }

            set
            {
                _stringSetting = value;

                OnPropertyChanged(() => StringSetting);
            }
        }

        /// <summary>
        /// Int setting
        /// </summary>
        public int IntSetting
        {
            get { return _intSetting; }
            
            set
            {
                _intSetting = value;

                OnPropertyChanged(() => IntSetting);
            }
        }

        #endregion

        #region Override

        /// <summary>
        /// Gets the description file.
        /// </summary>
        /// <value>The description file.</value>
        protected override string DescriptionFile
        {
            get { return "SettingsDescription.txt"; }
        }

        #endregion
    }
}